﻿using AutoMapper;
using JXC.Application.Dtos;
using JXC.Core.Models;
using JXC.Core.Repository;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace JXC.WebAPI.Controllers
{
    /// <summary>
    /// 仓库信息控制器
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    public class CinfoController : ControllerBase
    {
        private readonly IRepository<Cinfo, Guid> _repository;
        private readonly IMapper _mapper;
        public CinfoController(
               IRepository<Cinfo, Guid> repository,
               IMapper mapper
            )
        {
            _repository = repository;
            _mapper = mapper;
        }
        // GET: api/<CinfoController>
        [HttpGet]
        public async Task<IActionResult> Get()
        {
            var Cinfos = await _repository.GetAllListAsync();
            var CinfosDtoList = _mapper.Map<List<CinfoDto>>(Cinfos);
            return Ok(CinfosDtoList);
        }

        // GET api/<CinfoController>/5
        [HttpGet("{id}")]
        public async Task<IActionResult> Get(Guid id)
        {
            Cinfo cinfo = await _repository.SingleAsync(p => p.Id == id);
            CinfoDto shopDto = _mapper.Map<CinfoDto>(cinfo);
            return Ok(shopDto);
        }

        // POST api/<CinfoController>
        [HttpPost]
        public void Post([FromBody] string value)
        {
        }

        // PUT api/<CinfoController>/5
        [HttpPut("{id}")]
        public void Put(int id, [FromBody] string value)
        {
        }

        // DELETE api/<CinfoController>/5
        [HttpDelete("{id}")]
        public void Delete(int id)
        {
        }
    }
}
